home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3857 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Recursive function -> how do you exit one
  5. Date: 31 Jan 1996 16:49:44 GMT
  6. Organization: OpenVision
  7. Message-ID: <4eo6j8$pb3@spanky.pls.ov.com>
  8. References: <4eh1g8$aba@pulp.ucs.ualberta.ca>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article aba@pulp.ucs.ualberta.ca, jbukczyn@gpu.srv.ualberta.ca (Jacob Bukczynski) writes:
  13. >I'm using a recursive function to search for files. I need
  14. >it to quit when a user presses Esc.
  15. >
  16. >Using 
  17. >
  18. >return;
  19. >
  20. >doesn't seem to work, the funtion runs again. ( I tested
  21. >this by putting a printf statement in front of the return -
  22. >it got printed over and over again. )
  23. >
  24. >Is there a special way of exiting a recursive function?
  25. >
  26. >Please reply at jbukczyn@gpu.srv.ualberta.ca
  27. >
  28. >
  29.  
  30.  
  31. The standard library calls setjmp() and longjmp() were created for just
  32. the purpose you describe.  You use setjmp() to define where to go and 
  33. the stack environment, and if you execute longjmp(), you can avoid all of
  34. the deeply nested stacking represented by a recursive function.
  35. See K+R 2 pg.254 Section B8.
  36.  
  37.             Fletcher.Glenn@ov.com
  38.  
  39.  
  40.